﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.IO;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Security.Cryptography;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.ComponentModel;
using HospitalSystem.Core;
namespace HospitalSystem
{
    public partial class rightsinfo : System.Web.UI.Page
    {
        string strConnString = ConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
        private show_Image _showimage;
        private regfamilyLog _regf;
        private RegisterLog _RL;


        protected void Page_Load(object sender, EventArgs e)
        {
            _showimage = new show_Image();
            _regf = new regfamilyLog();
            _RL = new RegisterLog();

            showsession();
            _showimage.show_Images(cid_label, Image1);


            //if (Session["CID"] == null)
            //{

            //    MessageBoxurl("กรุณากดค้นหา หรือลงทะเบียนเด็กก่อน", "findchild.aspx");

            //}

            _RL.radiomedicalcare(medicalcare);

            _RL.radioyesno_1(yesno1);
            _RL.radioyesno_2(yesno2);

        }



        private void MessageBoxurl(string msg, string urld)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "');" + "window.location.href='" + urld + "';" + "</script>";
            Page.Controls.Add(lbl);
        }
        protected void showsession()
        {
            String ShowValue = (string)Session["CID"];
            cid_label.Text = ShowValue;
            String ShowValue2 = (string)Session["LastName"];
            lname.Text = ShowValue2;

            String ShowValue3 = (string)Session["FirstName"];
            fname.Text = ShowValue3;



        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            ImageUpload_f();


        //    Response.Redirect("~/Information.aspx");
        }

       






        protected void ImageUpload_f()
        {
            SqlConnection conn = new SqlConnection(strConnString);
            if (FileUploader.HasFile)
            {
                //try
                //{
                if (FileUploader.PostedFile.ContentType == "image/jpeg")
                {


                    conn.Open();
                    SqlCommand cmd = new SqlCommand("delete from pic_note where cid=@CID", conn);
                    cmd.Parameters.AddWithValue("@CID", cid_label.Text);
                    cmd.ExecuteNonQuery();

                    conn.Close();





                    //ไปใส่พาธไฟล์เอา

                    string MapPath = ("~/pic/note/");
                    string filename = cid_label.Text;
                    FileUploader.SaveAs(Server.MapPath(MapPath) + filename + ".Jpeg");
                    //FileUploader.SaveAs(filename + ".Jpeg");
                    // string SQL = "INSERT INTO [ImageDek] ([Iddek],[FilePath]) VALUES (@Iddek,@Filepath)";
                    //เพิ่มไฟล์ไทป์ด้วยนะคะพี่รงคะ
                    string Includepath = ((MapPath) + filename + ".Jpeg");
                    string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
                    SqlConnection scon = new SqlConnection(constr);
                    SqlCommand cmd22 = new SqlCommand("INSERT INTO [pic_note] ([cid],[FilePath]) VALUES (@Iddek,@Filepath)", scon);
                    cmd22.Parameters.AddWithValue("@Iddek", cid_label.Text);
                    cmd22.Parameters.AddWithValue("@FilePath", Includepath);



                    scon.Open();
                    cmd22.ExecuteNonQuery();
                    scon.Close();

                    //Response.Redirect("~/register.aspx");
                    //xxx คิวรีมาจาก db เอา
                    //Image1.ImageUrl = Server.MapPath("xxx");
                }
                else
                {
                }



                //}
                //catch
                //{

                //}
            }
        }
    }
}